package com.atguigu.springcloud.alibaba.myhandler;

import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.BlockExceptionHandler;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.alibaba.csp.sentinel.util.StringUtil;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;

@Component
public class myHandler implements BlockExceptionHandler {

        @Override
        public void handle(HttpServletRequest request, HttpServletResponse response, BlockException e) throws Exception {
            // Return 429 (Too Many Requests) by default.
            response.setStatus(429);

            StringBuffer url = request.getRequestURL();

            if ("GET".equals(request.getMethod()) && StringUtil.isNotBlank(request.getQueryString())) {
                url.append("?").append(request.getQueryString());
            }

            PrintWriter out = response.getWriter();
            out.print("wo shi zengbang hahaha！");
            out.flush();
            out.close();
        }

    }

